/*
 * 
 */
package edu.gatech.coc.betameisters.main;

import java.awt.Dimension;

import javax.swing.JFrame;

import edu.gatech.coc.betameisters.infoholders.Constants;
import edu.gatech.coc.betameisters.people.Doctor;
import edu.gatech.coc.betameisters.people.Nurse;
import edu.gatech.coc.betameisters.people.Patient;
import edu.gatech.coc.betameisters.people.Person;
import edu.gatech.coc.betameisters.people.SystemAdmin;
import edu.gatech.coc.betameisters.userinterfaces.LoginPanel;

/**
 * The Class DoctorsOffice.
 * 
 * @author Suren Nihalani
 * @version 1.0
 */
public class DoctorsOffice {
	private Person user;
	private MainPanel myMP;
	private JFrame mainFrame;

	public DoctorsOffice() {
		mainFrame = new JFrame("Doctors Office");
		user = null;
		myMP = new MainPanel();
		mainFrame.setVisible(true);
		mainFrame.setMinimumSize(new Dimension(300,300));
		//mainFrame.setMaximumSize(new Dimension(900,900));
		mainFrame.setResizable(true);
		mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		startUp();
	}

	private void startUp() {
		mainFrame.setMinimumSize(new Dimension(450,350));
		LoginPanel login = new LoginPanel();
		mainFrame.add(login);
		while (login.getLoggedIn() == null) {
			if (login.isExit()) {
				break;
			}
		}
		if (login.isExit()) {
			// exit the program/app
		} else {
			user = login.getLoggedIn();
			user.loggedIn();
			mainFrame.remove(login);
			branch();
		}
	}

	private void branch() {
		mainFrame.add(myMP);
		if (user == null) {
			startUp();
		} else if (user.getUserType() == Constants.UserType.PATIENT) {
			mainFrame.setMinimumSize(new Dimension(600,600));
			myMP.setPatient((Patient) user);
		} else if (user.getUserType() == Constants.UserType.NURSE) {
			mainFrame.setMinimumSize(new Dimension(900,900));
			System.out.println(user);
			myMP.setNurse((Nurse) user);
		} else if (user.getUserType() == Constants.UserType.DOCTOR) {
			System.out.println("DOCTOR");
			myMP.setDoctor((Doctor) user);
		} else if (user.getUserType() == Constants.UserType.ADMIN) {
			System.out.println("ADMIN");
			mainFrame.setMinimumSize(new Dimension(630,460));
			myMP.setMyAdmin((SystemAdmin) user);
		}
	}

	/**
	 * The main method.
	 * 
	 * @param args
	 *            the arguments whataever you give, none of them are used.
	 */
	public static void main(String[] args) {
		new DoctorsOffice();

	}

	/**
	 * String representation for this class.
	 * 
	 * @return the representation.
	 */
	public String toString() {
		return "The main DoctorsOffice class";
	}
}
